package cn.iocoder.yudao.module.system.convert.investment;

import cn.iocoder.yudao.module.system.controller.admin.investment.vo.ParticipationRespVO;
import cn.iocoder.yudao.module.system.dal.dataobject.investment.SystemInvestment;
import cn.iocoder.yudao.module.system.dal.dataobject.investment.SystemParticipation;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 梁富贵
 * @Date 2024/10/11
 **/
public class ParticipationConvertToResp {

    /**
     * 将SystemParticipation转换成ParticipationRespVO
     * @param systemParticipations
     * @return
     */
    public static List<ParticipationRespVO> toResp(List<SystemParticipation> systemParticipations) {
        return systemParticipations.stream()
                .map(systemParticipation -> {
                    ParticipationRespVO participationRespVO = new ParticipationRespVO();
                    participationRespVO.setId(systemParticipation.getId());
                    participationRespVO.setCompanyName(systemParticipation.getCompanyName());
                    participationRespVO.setLegalRepresentative(systemParticipation.getLegalRepresentative());
                    participationRespVO.setPhone(systemParticipation.getPhone());

                    // 处理 address 字段
                    participationRespVO.setAddress(splitString(systemParticipation.getAddress(), ","));

                    participationRespVO.setStatus(systemParticipation.getStatus());
                    participationRespVO.setApplicationDate(systemParticipation.getApplicationDate());
                    participationRespVO.setApprovalDate(systemParticipation.getApprovalDate());
                    participationRespVO.setNotes(systemParticipation.getNotes());

                    // 处理 applicationFile 字段
                    participationRespVO.setApplicationFile(splitString(systemParticipation.getApplicationFile(), ","));

                    // 处理 qualificationFile 字段
                    participationRespVO.setQualicationFile(splitString(systemParticipation.getQualicationFile(), ","));

                    return participationRespVO;
                })
                .collect(Collectors.toList());
    }

    private static String[] splitString(String input, String delimiter) {
        if (input == null || input.isEmpty()) {
            return new String[0];
        }
        return input.split(delimiter);
    }
}
